from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.get("/hello/{name}")
async def say_hello(name: str):
    return {"message": f"Hello {name}"}


# 步骤3&4: 定义路径操作
@app.get("/items/{item_id}")
async def read_item(item_id: int):
    # 假设这里是获取物品信息的逻辑
    return {"item_id": item_id, "name": "Sample Item"}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app,
                host="127.0.0.1",
                port=8000,
                reload=True)
